# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=cegui
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.8.4
pkgrel=1
pkgdesc="A free library providing windowing and widgets for graphics APIs/engines (mingw-w64)"
arch=('any')
url="http://cegui.org.uk"
license=("MIT")
#makedepends=('doxygen' 'gtk2' 'graphviz' 'irrlicht' 'glm' 'tolua++')
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
    "${MINGW_PACKAGE_PREFIX}-pkg-config"
    "${MINGW_PACKAGE_PREFIX}-cmake"
    "${MINGW_PACKAGE_PREFIX}-python2"
    "mercurial")
depends=("${MINGW_PACKAGE_PREFIX}-tinyxml"
    "${MINGW_PACKAGE_PREFIX}-boost"
    "${MINGW_PACKAGE_PREFIX}-DevIL"
    "${MINGW_PACKAGE_PREFIX}-expat"
    "${MINGW_PACKAGE_PREFIX}-FreeImage"
    "${MINGW_PACKAGE_PREFIX}-freetype"
    "${MINGW_PACKAGE_PREFIX}-fribidi"
    "${MINGW_PACKAGE_PREFIX}-glew"
    #"${MINGW_PACKAGE_PREFIX}-glfw"
    "${MINGW_PACKAGE_PREFIX}-glm"
    "${MINGW_PACKAGE_PREFIX}-irrlicht"
    "${MINGW_PACKAGE_PREFIX}-libxml2"
    "${MINGW_PACKAGE_PREFIX}-libiconv"
    "${MINGW_PACKAGE_PREFIX}-lua51"
    "${MINGW_PACKAGE_PREFIX}-ogre3d"
    "${MINGW_PACKAGE_PREFIX}-ois"
    "${MINGW_PACKAGE_PREFIX}-pcre"
    #"${MINGW_PACKAGE_PREFIX}-tolua"
    "${MINGW_PACKAGE_PREFIX}-xerces-c"
    "${MINGW_PACKAGE_PREFIX}-zlib")
options=('staticlibs' 'strip')
source=("https://downloads.sourceforge.net/crayzedsgui/cegui-${pkgver}.tar.bz2"
    freetype.patch
    mingw-w64-fix.patch
    fix-finding-glew.patch
    fix-finding-directx.patch
    fix-finding-glfw3.patch
    fix-dxerr-libname.patch)
sha256sums=('b5fcbd548b83045e92c4da413928113be77ebee0117368925e1904b3b957a388'
            '83e84d862a195c61901b0dd53a1c47434b812fff15fb977f390a45f19dcc4a64'
            '31e666ea015b30b9ee939b69994255eacb2e75fa9dec86538715e4b9a026863a'
            'c7ad92f3ce9ba0f23ca1a6928b69c7ad041af94ece860de59ddce616c1ec311c'
            'c4e16b620b3881e35333bef41b4c38378d965bfdd215b32cc94c73816bb9d24f'
            '181385b172f952265a0be6a96eccd0ab9d4cb8846f7e07cd5d5e5095a0a591a0'
            '85d5dec0ff7d6a7cd3b98057b910a0ab4eafaedd68d45bfd5fd70093fa0c35a1')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  #patch -p1 -i ${srcdir}/freetype.patch
  #patch -p1 -i ${srcdir}/mingw-w64-fix.patch
  patch -p1 -i ${srcdir}/fix-finding-glew.patch
  patch -p1 -i ${srcdir}/fix-finding-directx.patch
  #patch -p1 -i ${srcdir}/fix-finding-glfw3.patch
  patch -p1 -i ${srcdir}/fix-dxerr-libname.patch
}

build() {
  mkdir -p ${pkgdir}${MINGW_PREFIX}
  pushd ${pkgdir}${MINGW_PREFIX} > /dev/null
  export PREFIX_WIN=`pwd -W`
  popd > /dev/null

  pushd ${MINGW_PREFIX} > /dev/null
  export PREFIX_DEPS=`pwd -W`
  popd > /dev/null

  mkdir $srcdir/build-${MINGW_CHOST}
  cd "$srcdir/build-${MINGW_CHOST}"

  export DXSDK_DIR=${PREFIX_DEPS}/${MINGW_CHOST}
  export CFLAGS="-I${PREFIX_DEPS}/include"
  export CXXFLAGS="-I${PREFIX_DEPS}/include"
  #cd "${srcdir}/${_realname}-${pkgver}"
  ${MINGW_PREFIX}/bin/cmake.exe \
    ../${_realname}-${pkgver} \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX:PATH=${PREFIX_WIN} \
    -DCEGUI_LIB_INSTALL_DIR=lib \
    -DCEGUI_BUILD_PYTHON_MODULES=OFF # currently broken :(
    # -PYTHON_EXECUTABLE=/usr/bin/python2
  make
  #make html
}

package() {
  cd "$srcdir/build-${MINGW_CHOST}"
  make -j1 install
}
